#include "event.h"

extern "C" 
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
};

#include "lua_tinker.h"

lua_State* L = NULL;

class Test
{
public:
    Test()
    {   
        x = 11;
    }

    void setX(long long ax)
    {
        x = ax;
    }

    long long getX()
    {
        return x;
    }

private:
    long long     x;
};

void script_handler(struct object_s* root, struct object_s* observer, void* data, void* arg)
{
    lua_tinker::call<void>(L, (char*)data, root, observer, arg);
}

#include <iostream>
using namespace std;

enum EVENT_TYPE
{
    EVENT_1,
};

int main()
{
    struct object_s* a = object_create();
    object_insert_handler(a, EVENT_1, (event_handler_pt)script_handler, (void*)"main");

    L = luaL_newstate();
    luaopen_base(L);

    lua_tinker::class_add<Test>(L, "Test");

    lua_tinker::class_def<Test>(L, "setX", &Test::setX);
    lua_tinker::class_def<Test>(L, "getX", &Test::getX);

    lua_tinker::dofile(L, "main.lua");
    lua_tinker::dofile(L, "test.lua");

    object_handler(a, a, EVENT_1, 0);
    cin.get();
    return 0;
}